package com.neu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.neu.service.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 用户管理Controller
 * @author Admin
 *
 */
@Controller
@RequestMapping("/users")
public class UserController {
	
	@Autowired
	private UserService userService;
	@Autowired
	private HttpServletRequest request;
	
	@RequestMapping("/index")
	public ModelAndView  index() {
		//代码编写处
		ModelAndView modelAndView = new ModelAndView();

		HttpSession session = request.getSession();

		Object user = session.getAttribute("user");

		if(user == null){
			modelAndView.setViewName("redirect:/index");

		}else{
			modelAndView.addObject("userList",userService.getUsers());
			modelAndView.setViewName("/users");
		}
		return modelAndView; //请修改代码
	}
}
